/**
 * Created by seeker910 on 2017/6/19.
 * 向导步骤 列表页
 */
Rsd.define('Rsd.zen.dialog.ListGuider', {
    extend: 'Rsd.container.Guider',
    requires: [ 'Rsd.control.Grid'],
    xtype: 'list-guider',
    width: '100%',
    layout: 'fit',
    items:[
        {
            xtype:'grid',
            margin: '0 1 0 0',
            rowdblclick: null,
            toolBar:null,
            footBar:null
        }
    ],
    footBar:null,
    toolBar:null,
    /*
     * */
    constructor: function ListGuider(config) {
        config = config || {};
        this.apply(config); 
    },
    /*
     *
     * */
    onBeforeInit:function onBeforeInit( ) {
 
        if(this.footBar) { 
            this.items[0].footBar = this.footBar;
        }
        if(this.toolBar)
        {
            this.items[0].toolBar = this.toolBar;
        }
        this.callParent();
    },
    /*
     args :api 接口需要的参数
     * */
    load:function load(callback) {
        //debugger;
        var me = this;
         me.items[0].loadData(me.data);
        if(me.onLoad || me.onload)
        {
            me.funApplyByIOC(me.onLoad || me.onload,[me,callback]);
        }
        else
       {
            callback(me);
       } 
        
       return this;
    },
    /*
     * @private
     * */
    buildGridColumns:function buildGridColumns() {
        
        var _cols = this.gridColumns; 
        //为列自动关联 format 方法
        for(var i in _cols)
            {
                var c = _cols[i];
                if(!c || c.format)
                {
                    continue;
                }
                if(this['format'+c.name])
                {
                    c.format = 'format' + c.name; 
                }
            }
            
        _cols.push({
            name: 'space',
            text: '',
            xtype: 'template',
            width: 5,
            fixed:true,
            hideable: false,
            sortable: false
        })
        var grid = this.items[0];
        if(grid instanceof Rsd.control.Grid)
        {
            grid.buildColumns(_cols);
        }
        else
        {
            grid.columns = _cols;
        }
    },

    /**
     *  @description 获取表格的数据
     * */
    getData:function getData()
    {
        var grid = this.items[0];
        return grid.getData();
    },
    /*
    * @description 获取表格的数据
    *  */
    getDataSource:function getDataSource(args,callback) {
        console.log('not set getDataSource(args,callback)');
        return [];
    }
  

},function (type) {

    var _columnsGetter = function () {
        if(this.__gridColumns == undefined)
        {
            this.__gridColumns = [];
        }
        return this.__gridColumns;
    };

    var _columnsSetter = function (value) {
        this.__gridColumns = value;

        this.buildGridColumns();
    }

    this.defineProperty(type,"gridColumns", _columnsGetter, _columnsSetter,true);

    this.defineProperty(type,'grid', function(){return this.items[0];}, function(value){ this.items[0] = value; }, false);

});